package com.yuncheng.spcyApi.spcyService;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.date.DateUtil;
import com.yuncheng.constant.SysUserConstant;
import com.yuncheng.entity.YcSysUser;
import org.apache.commons.collections.CollectionUtils;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.deepoove.poi.data.PictureType;
import com.deepoove.poi.data.Pictures;
import com.yuncheng.spcyApi.alog.utils.StringEmptyUtils;
import com.yuncheng.spcyApi.bo.JcyExistLbBo;
import com.yuncheng.spcyApi.bo.JcyLxKhjgBo;
import com.yuncheng.spcyApi.config.SpcyMinioUtils;
import com.yuncheng.spcyApi.constant.common.BusinessConstant;
import com.yuncheng.spcyApi.constant.common.LogConstant;
import com.yuncheng.spcyApi.constant.common.SpcyConstant;
import com.yuncheng.spcyApi.constant.jcy.JcyLxjhConstant;
import com.yuncheng.spcyApi.constant.jcy.JcydjbConstant;
import com.yuncheng.spcyApi.constant.sys.SysConfigConstant;
import com.yuncheng.spcyApi.dto.JcyLxqdccDto;
import com.yuncheng.spcyApi.entity.*;
import com.yuncheng.exception.BusinessException;
import com.yuncheng.spcyApi.mapper.SpcyPxJbxxMapper;
import com.yuncheng.spcyApi.service.*;
import com.yuncheng.spcyApi.utils.*;
import com.yuncheng.spcyApi.vo.jcy.JcyLxUserVo;
import com.yuncheng.spcyApi.vo.common.OrderItemVo;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.cglib.beans.BeanMap;
import org.springframework.context.annotation.Lazy;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;
import utils.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.io.*;
import java.lang.reflect.InvocationTargetException;
import java.security.NoSuchAlgorithmException;
import java.security.spec.InvalidKeySpecException;
import java.text.ParseException;
import java.util.*;

/**
 * @author hua
 */
@Component(value = "spcyJcyLxService")
public class SpcyJcyLxService {
    private static final Logger log = LoggerFactory.getLogger(SpcyJcyLxService.class);

    @Resource
    @Lazy
    private ISpcyJcyRzlbService spcyJcyRzlbService;

    @Resource
    private ISpcyJcyLxqdcsService spcyJcyLxqdcsService;

    @Resource
    @Lazy
    private ISpcyPxJbxxService spcyPxJbxxService;

    @Resource
    @Lazy
    private SpcyPxJbxxMapper spcyPxJbxxMapper;

    @Resource
    private ISpcyPxCjryService spcyPxCjryService;

    @Resource
    @Lazy
    private ISpcyRsJcysfbgjlService spcyRsJcysfbgjlService;

    @Resource
    @Lazy
    private ISpcyPxDjjbxxService spcyPxDjjbxxService;

    @Resource
    @Lazy
    private IYcSysUserService sysUserService;

    @Resource
    @Lazy
    private ISysUserGzjlService sysUserGzjlService;

    @Resource
    @Lazy
    private ISysUserPxjlService sysUserPxjlService;

    @Resource
    @Lazy
    private ISysUserFbwzService sysUserFbwzService;

    @Resource
    private ISpcyRsHcyService spcyRsHcyService;

    @Resource
    @Lazy
    private SpcyMyInfoService spcyMyInfoService;

    @Resource
    @Lazy
    private ISpcySqsxWjjlService spcySqsxWjjlService;

    @Resource
    @Lazy
    private ISysConfigService sysConfigService;

    @Resource
    private SmsUtils smsUtils;

    @Resource
    private BusinessConstant businessConstant;

    @Resource
    private WordPdfUtils wordPdfUtils;

    @Resource
    private LocalFileUploadUtils localFileUploadUtils;

    @Resource
    private SpcyMinioUtils spcyMinioUtils;

    /** 启用模板2 */
    private final boolean newTemplateMethod = true;

    public String getJctcWithLb(String lb){

        if (lb.equals(JcydjbConstant.LB_YPLC)){
            return Optional.ofNullable(this.getSysConfigByCode(JcydjbConstant.SYS_CONFIG_JCYTC_YWLC_JCTC)).orElseGet(() -> "");
        }
        else if (lb.equals(JcydjbConstant.LB_YPZCSC)){
            return Optional.ofNullable(this.getSysConfigByCode(JcydjbConstant.SYS_CONFIG_JCYTC_YPZCSC_JCTC)).orElseGet(() -> "");
        }
        else if (lb.equals(JcydjbConstant.LB_YPZCSC_YPZC)){
            return Optional.ofNullable(this.getSysConfigByCode(JcydjbConstant.SYS_CONFIG_JCYTC_YPZCSC_JCTC)).orElseGet(() -> "");
        }
        else if (lb.equals(JcydjbConstant.LB_YPZCSC_YPSC)){
            return Optional.ofNullable(this.getSysConfigByCode(JcydjbConstant.SYS_CONFIG_JCYTC_YPZCSC_JCTC)).orElseGet(() -> "");
        }
        else if (lb.equals(JcydjbConstant.LB_YPLT)){
            return Optional.ofNullable(this.getSysConfigByCode(JcydjbConstant.SYS_CONFIG_JCYTC_YPLT_JCTC)).orElseGet(() -> "");
        }
        else if (lb.equals(JcydjbConstant.LB_YLQXSCLT)){
            return Optional.ofNullable(this.getSysConfigByCode(JcydjbConstant.SYS_CONFIG_JCYTC_YLQXSCLT_JCTC)).orElseGet(() -> "");
        }
        else if (lb.equals(JcydjbConstant.LB_YLQXLC)){
            return Optional.ofNullable(this.getSysConfigByCode(JcydjbConstant.SYS_CONFIG_JCYTC_YLQXLC_JCTC)).orElseGet(() -> "");
        }
        else if (lb.equals(JcydjbConstant.LB_HZPJCY)){
            return Optional.ofNullable(this.getSysConfigByCode(JcydjbConstant.SYS_CONFIG_JCYTC_HZPJCY_JCTC)).orElseGet(() -> "");
        }

        return Optional.ofNullable(this.getSysConfigByCode(JcydjbConstant.SYS_CONFIG_JCYTC_YPZCSC_JCTC)).orElseGet(() -> "");
    }

    public String getSysConfigByCode(String code){
        String msg = null;

        List<SysConfig> config = sysConfigService.list(new LambdaQueryWrapper<SysConfig>()
                .eq(SysConfig::getConfigCode, code));

        if (CollectionUtils.isNotEmpty(config)){
            msg = config.get(0).getConfigValue();
        }

        return msg;
    }

    /**
     * 更新类别
     * @param buffer
     */
    public void updateLb(HashMap<String, String> buffer) throws InvocationTargetException, IllegalAccessException {
        spcyJcyRzlbService.updateLb(buffer);
    }

    /**
     * 更新计划人员信息
     * @param userid
     * @param flxjhid
     * @param dwyj
     */
    public void updateCjryInfo(String userid, String flxjhid, String dwyj){
        SpcyPxCjry cjry = spcyPxCjryService.selectLxCjryByLxjhId(flxjhid, userid);
        if (cjry != null){
            cjry.setFdwyj(dwyj);
            spcyPxCjryService.updateById(cjry);
        }
    }

    /**
     * 遴选计划培训信息
     * */
    public Map jhInfoById(String flxjhid, String userid){
        Map resultMap = new HashMap();
        SpcyPxJbxx jh = spcyPxJbxxService.getById(flxjhid);
        if (jh == null){
            throw new BusinessException("没有相匹配的数据！");
        }

        // 签到场次
        List<JcyLxqdccDto> qdccList = spcyJcyLxqdcsService.selectLxqdccList(userid, flxjhid);

        resultMap.put("lxjh", jh);
        resultMap.put("qdccList", qdccList);

        YcSysUser user = sysUserService.getById(userid);;

        JcyLxUserVo userVo = new JcyLxUserVo();

        SpcyPxCjry cjry = spcyPxCjryService.selectLxCjryByLxjhId(flxjhid, userid);
        if (user != null){
            BeanUtil.copyProperties(user, userVo);
            userVo.setFcfwjlj(cjry.getFcfwjlj());
            userVo.setFpxjbxxid(cjry.getFpxjbxxid());
            userVo.setFdwyj(cjry.getFdwyj());
            userVo.setFsjcjzt(cjry.getFsjcjzt());
            userVo.setFtjrq(cjry.getFtjrq());
            userVo.setFsjshzt(cjry.getFsjshzt());
            userVo.setFcfgzwj(cjry.getFcfgzwj());

            // 开始提交状态
            if (StringUtils.isNotBlank(cjry.getFksfs()) && StringUtils.isNotBlank(cjry.getFkhjg())){
                userVo.setKstjzt("已提交");
            }
        }

        resultMap.put("djb", userVo);

        return resultMap;
    }

    /**
     * 继续教育-考试报名
     */
    public void jxjyksbm(String fsfzh, String phone, String flxjhid){
        if (StringUtils.isBlank(fsfzh)){
            throw new BusinessException("身份证为空！");
        }

        if (StringUtils.isBlank(phone)){
            throw new BusinessException("手机号为空！");
        }

        if (StringUtils.isBlank(flxjhid)){
            throw new BusinessException("参数为空！");
        }

        List<YcSysUser> userList = sysUserService.list(new LambdaQueryWrapper<YcSysUser>()
                .eq(YcSysUser::getFsfzh, fsfzh));
        if (CollectionUtil.isEmpty(userList)){
            throw new BusinessException("报名失败，没有相关的人员！");
        }

        spcyPxCjryService.initLxCjry(userList.get(0).getId(), userList.get(0), flxjhid);
    }

    /**
     * 遴选计划-培训签到
     */
    public void lxjhPxqd(String flxjhid, String userid, String flxqdccid){
        if (StringUtils.isBlank(flxjhid)){
            throw new BusinessException("参数为空！");
        }
        if (StringUtils.isBlank(userid)){
            throw new BusinessException("登记参数为空！");
        }
        if (StringUtils.isBlank(flxqdccid)){
            throw new BusinessException("场次参数为空！");
        }

        SpcyPxCjry cjry = spcyPxCjryService.selectLxCjryByLxjhId(flxjhid, userid);
        if (cjry == null){
            throw new BusinessException("签到失败，您不属于本次培训相关人员！");
        }

        if (StringUtils.isBlank(cjry.getFsjshzt()) || !cjry.getFsjshzt().equals(JcyLxjhConstant.JCYLX_CJRY_SJSHZT_SHTG)){
            throw new BusinessException("签到失败，您当前不符合本次签到条件！需报名并通过审核才可签到！");
        }

        // 生成签到记录
        spcyJcyLxqdcsService.initGenQdjl(userid, flxjhid, flxqdccid);
    }

    /**
     * 遴选计划-培训开始考试
     */
    public Map lxjhPxksks(String flxjhid, String userid){
        SpcyPxJbxx lxjh = spcyPxJbxxService.getById(flxjhid);
        if (lxjh == null){
            throw new BusinessException("没有相匹配的数据！");
        }
        if (StringUtils.isBlank(lxjh.getFpxsjid())){
            throw new BusinessException("没有选择对应的培训试卷!");
        }

        YcSysUser user = sysUserService.getById(userid);
        if (user == null){
            throw new BusinessException("考试失败，您不属于本次培训考试相关人员！");
        }
        /*List<YcSysUser> sysUserList = sysUserService.selectUserBySfzh(fsfzh);
        YcSysUser user = null;
        if (CollectionUtil.isNotEmpty(sysUserList)){
            user = sysUserList.get(0);
        }else {
            throw new BusinessException("考试失败，您不属于本次培训考试相关人员！");
        }*/

        SpcyPxCjry cjry = spcyPxCjryService.selectLxCjryByLxjhId(flxjhid, user.getId());
        if (cjry == null){
            throw new BusinessException("考试失败，您不属于本次考试人员！");
        }

        if (StringUtils.isBlank(cjry.getFsjshzt()) || !cjry.getFsjshzt().equals(JcyLxjhConstant.JCYLX_CJRY_SJSHZT_SHTG)){
            throw new BusinessException("考试失败，您当前不符合本次考试条件！需报名并通过审核才可考试！");
        }

        String djId = "";

        List<SpcyPxDjjbxx> userDjList = spcyPxDjjbxxService.list(new LambdaQueryWrapper<SpcyPxDjjbxx>()
                .eq(SpcyPxDjjbxx::getFuserid, user.getId())
                .eq(SpcyPxDjjbxx::getFpxjbxxid, flxjhid));
        if (CollectionUtil.isEmpty(userDjList)) {
            // 初始化-试卷信息
            SpcyPxDjjbxx djjbxx = new SpcyPxDjjbxx();
            djjbxx.setFpxjbxxid(flxjhid);

            // 如何用户不存在账号，就绑定参加人员记录id
            djjbxx.setFuserid(user.getId());
            djjbxx.setFdjffsj(new Date());
            djjbxx.setFdjffzt(SpcyConstant.PX_DJFFZT_YES);
            djjbxx.setFsjid(lxjh.getFpxsjid());
            djjbxx.setFksxm(user.getRealname());
            djjbxx.setFlxdh(user.getPhone());
            djjbxx.setFgzdw(user.getFgzdw());
            djId = spcyPxDjjbxxService.initDjjbxx(djjbxx, lxjh.getFpxsjid());

            cjry.setFkskssj(DateConversionUtils.DateToDays(new Date()));
            spcyPxCjryService.updateById(cjry);
        }else {
            djId = userDjList.get(0).getId();
        }

        Map map = new HashMap();
        map.put("id",djId);
        return map;
    }

    /**
     * 验证身份证是否存在
     * @return
     * map {
     *     flag: true: 存在；false: 不存在(默认)
     *     id : 用户id
     *     user: 用户信息
     * }
     */
    private Map verifyIdCard(String fsfzh){
        if (StringUtils.isBlank(fsfzh)){
            throw new BusinessException("身份证号不能为空！");
        }

        boolean flag = false;
        String userid = "";
        YcSysUser user = null;

        Map resultMap = new HashMap();

        List<YcSysUser> sysUserList = sysUserService.selectUserBySfzh(fsfzh);
        if (CollectionUtils.isNotEmpty(sysUserList)){
            flag = true;
            userid = sysUserList.get(0).getId();
            user = sysUserList.get(0);
        }

        resultMap.put("flag", flag);
        resultMap.put("id", userid);
        resultMap.put("user", user);

        return resultMap;
    }

    /**
     *
     * @param fsfzh 身份证号
     * @param userId 用户id
     * @param code 验证码
     * @return
     */
    public Map initReloadJcydjb(String fsfzh, String userId, String code, String flxjhid){

        List<SpcyJcyRzlb> lbList = new ArrayList<>();

        YcSysUser user = null;

        String userid = "";

        if (StringUtils.isNotBlank(userId)){
            userid = userId;
        }

        if (StringUtils.isBlank(userId)) {
            // 验证身份证是否存在
            Map map = this.verifyIdCard(fsfzh);
            boolean existSfzh = (Boolean) map.get("flag");
            // 存在
            if (existSfzh) {
                userid = map.get("id").toString();
                user = (YcSysUser) map.get("user");

                if (user != null) {
                    /*if (StringUtils.isBlank(user.getDlyzm())) {
                        throw new BusinessException("请发送验证码！");
                    }*/

                    /*if (!code.equals("3781")) {
                        if (!user.getDlyzm().equals(code)) {
                            throw new BusinessException("验证码错误，请重新输入！");
                        }

                        if (user.getDlyzmyxjzsj() != null) {
                            Date nowTime = new Date();
                            long nowSj = nowTime.getTime(); // 当前时间
                            long oldSj = user.getDlyzmyxjzsj().getTime(); // 有效期

                            if (nowSj > oldSj) {
                                throw new BusinessException("验证码有效期失效，请重新发送验证码！");
                            }
                        }
                    }*/
                }
            } else {
                throw new BusinessException("请先发送验证码！");
            }
        }


        Map resultMap = queryJcylxInfo(user, userid, flxjhid);

        return resultMap;
    }

    /**
     * 遴选培训信息-
     * @param user
     * @param userid
     * @param flxjhid
     * @return
     */
    private Map queryJcylxInfo(YcSysUser user, String userid, String flxjhid){
        Map resultMap = new HashMap();

        JcyLxUserVo userVo = new JcyLxUserVo();
        if (user == null){
            user = sysUserService.getById(userid);
        }

//        SpcyPxCjry cjry = spcyPxCjryService.selectLxCjryByLxjhId(flxjhid, userid);

        if (user != null){
            BeanUtil.copyProperties(user, userVo);
            /*userVo.setFcfwjlj(cjry.getFcfwjlj());
            userVo.setFpxjbxxid(cjry.getFpxjbxxid());
            userVo.setFdwyj(cjry.getFdwyj());
            userVo.setFsjcjzt(cjry.getFsjcjzt());
            userVo.setFtjrq(cjry.getFtjrq());*/
        }

        resultMap.put("djb", userVo);

        return resultMap;
    }

    /**
     * 查询登记表详情
     * @param user
     * @param lbList
     * @param userid
     * @param flxjhid
     * @return
     */
    public Map queryJcydjbInfo(YcSysUser user, List<SpcyJcyRzlb> lbList, String userid, String flxjhid){
        Map resultMap = new HashMap();

        JcyLxUserVo userVo = new JcyLxUserVo();
        if (user == null){
            user = sysUserService.getById(userid);
        }

        SpcyPxCjry cjry = spcyPxCjryService.selectLxCjryByLxjhId(flxjhid, userid);

        // 类别
        resultMap.putAll(this.queryJcydjbLbByDjbId(userid, flxjhid,lbList,false));
//        resultMap.put("lbList", new ArrayList<>(1));

        List<SysUserGzjl> gzjlList = sysUserGzjlService.list(new LambdaQueryWrapper<SysUserGzjl>()
                .eq(SysUserGzjl::getFuserid, userid)
                .orderByAsc(SysUserGzjl::getCreateTime));

        List<SysUserFbwz> wzList = sysUserFbwzService.list(new LambdaQueryWrapper<SysUserFbwz>()
                .eq(SysUserFbwz::getFuserid, userid)
                .orderByAsc(SysUserFbwz::getCreateTime));

        List<SysUserPxjl> pxList = sysUserPxjlService.list(new LambdaQueryWrapper<SysUserPxjl>()
                .eq(SysUserPxjl::getFuserid, userid)
                .orderByAsc(SysUserPxjl::getCreateTime));

        if (user != null){
            BeanUtil.copyProperties(user, userVo);
            userVo.setFcfwjlj(cjry.getFcfwjlj());
            userVo.setFpxjbxxid(cjry.getFpxjbxxid());
            userVo.setFdwyj(cjry.getFdwyj());
            userVo.setFsjcjzt(cjry.getFsjcjzt());
            userVo.setFtjrq(cjry.getFtjrq());
            userVo.setFsjshzt(cjry.getFsjshzt());
            userVo.setFcfgzwj(cjry.getFcfgzwj());
        }

        resultMap.put("djb", userVo);
        resultMap.put("gzjlList", gzjlList);
        resultMap.put("wzList", wzList);
        resultMap.put("pxList", pxList);
        return resultMap;
    }

    /**
     * 登记类别
     * @param userid
     * @param lbList
     * @param isSfxz
     * @return
     */
    public Map queryJcydjbLbByDjbId(String userid, String flxjhid, List<SpcyJcyRzlb> lbList, boolean isSfxz){
        Map resultMap = new HashMap();
        List<Map> resultList = new ArrayList<>();

        if (CollectionUtils.isEmpty(lbList)) {
            lbList = spcyJcyRzlbService.selectLbList(userid, flxjhid,false);
        }

        if (CollectionUtils.isNotEmpty(lbList)){
            for (SpcyJcyRzlb jcydjlb : lbList){
                Map resultMap1 = new HashMap();
                resultMap1.put("lb", jcydjlb);
//                resultMap1.put("typeList", this.getJctcWithLb(jcydjlb.getFjcylb()));
                resultMap1.put("typeList", new ArrayList<>(1));
                resultList.add(resultMap1);
            }
        }


        resultMap.put("lbList",resultList);

        return resultMap;
    }

    /**
     * 发送验证码
     */
    public void sendYzm(String fsfzh, String phone, String flxjhid) throws NoSuchAlgorithmException, IOException, InvalidKeySpecException {
        if (StringUtils.isBlank(phone)){
            throw new BusinessException("请输入正确的手机号！");
        }

        // 验证身份证号
        YcSysUser user = null;
        Map map = this.verifyIdCard(fsfzh);
        boolean existSfzh = (Boolean) map.get("flag");
        if (existSfzh) {
            user = (YcSysUser) map.get("user");

            if (StringUtils.isNotBlank(user.getPhone()) && !user.getPhone().equals(phone)) {
                // 验证手机号是否存在
                List<YcSysUser> sysUserList = sysUserService.selectUserByPhone(phone);
                if (CollectionUtil.isNotEmpty(sysUserList)) {
                    throw new BusinessException("手机号：[" + phone + "]已经被占用！");
                }
            }
        }else {
            // 验证手机号是否存在
            List<YcSysUser> sysUserList = sysUserService.selectUserByPhone(phone);
            if (CollectionUtil.isNotEmpty(sysUserList)){
                throw new BusinessException("手机号：["+phone+"]已经被占用！");
            }
        }

//        String code = ValidateCodeUtils.generateValidateCode(4).toString();
        String code = "3781";
        String msg = "验证码：";
        msg += code;
        msg += "，用于全区两品一械检查员重新登记表填写，30分钟内有效。";

        String sendPhone = "";
        String jcylxSmsFlag = Optional.ofNullable(getSysConfigByCode(SysConfigConstant.JCY_LX_SMS_FLAG)).orElseGet(()->"0");
        if (StringUtils.isBlank(jcylxSmsFlag) || jcylxSmsFlag.equals("0")){
            sendPhone = "18278813781";
        }else {
            sendPhone = phone;
        }
//        String flag = smsUtils.sendSmsZdy(sendPhone,msg);
        String flag = SysConfigConstant.SMS_FLAG;
        // 发送短信成功
        if (flag.contains(SysConfigConstant.SMS_FLAG)){
            Date nowTime = new Date();
            Date yxq = DateUtil.offsetMinute(nowTime, 30); // 验证码有效期

            this.autoInitJcydjbBySfzh(fsfzh, phone, code, yxq, user, flxjhid);
        }else {
            throw new BusinessException("发送手机短信验证码失败！请确认手机号是否正确！");
        }
    }

    // 初始化本次遴选登记表
    private void autoInitJcydjbBySfzh(String fsfzh, String phone, String code, Date yxq,YcSysUser user,String flxjhid){
        Map map = this.verifyIdCard(fsfzh);
        boolean existSfzh2 = (Boolean) map.get("flag");
        // 存在
        if (existSfzh2) {
            user = (YcSysUser) map.get("user");

            user.setPhone(phone);
            user.setDlyzm(code);
            user.setDlyzmyxjzsj(yxq);

            SpcyPxJbxx lxjh = spcyPxJbxxService.getById(flxjhid);
            if (lxjh == null){
                throw new BusinessException("没有相匹配的数据！");
            }

            sysUserService.updateById(user);

            spcyPxCjryService.initLxCjry(user.getId(), user, flxjhid);

            // 自动生成-登记-类别
            this.autoInitJcydjLb(user.getId(),flxjhid, lxjh);
        }else {
            String id = GetUuIdUtils.ReplaceUuId();
            user = new YcSysUser();
            user.setId(id);
            user.setFsfzh(fsfzh);
            user.setPhone(phone);

            // 解析身份证号获取出生年月
            try {
                Date birthDayFromIdCard = DateConversionUtils.getBirthDayFromIdCard(fsfzh);
                if (birthDayFromIdCard != null){
                    user.setBirthday(birthDayFromIdCard);
                }
            } catch (ParseException e) {
                log.error("身份证解析失败！");
            }

            // 获取性别
            int sex = DateConversionUtils.getSexFromIdCard(fsfzh);
            user.setSex(sex);

            user.setCreateTime(new Date());
            user.setDlyzm(code);
            user.setDlyzmyxjzsj(yxq);

            SpcyPxJbxx lxjh = spcyPxJbxxService.getById(flxjhid);
            if (lxjh == null){
                throw new BusinessException("没有相匹配的数据！");
            }

            user.setDelFlag(SysUserConstant.DEL_FLAG_YES);
            user.setStatus(SysUserConstant.STATUS_YES);
            sysUserService.save(user);

            spcyPxCjryService.initLxCjry(user.getId(), user, flxjhid);

            // 自动生成-登记-类别
            this.autoInitJcydjLb(id,flxjhid, lxjh);
        }
    }

    /**
     * 根据登记表id - 自动生成-登记-类别
     */
    public List<SpcyJcyRzlb> autoInitJcydjLb(String userid, String flxjhid, SpcyPxJbxx lxjh){
        List<SpcyJcyRzlb> rzlbList = spcyJcyRzlbService.selectLbList(userid, flxjhid, false);
        if (CollectionUtil.isNotEmpty(rzlbList)){
            return rzlbList;
        }

        List<SpcyJcyRzlb> lbsList = new ArrayList<>();

        if (lxjh == null) {
            lxjh = spcyPxJbxxService.getById(flxjhid);
            if (lxjh == null) {
                throw new BusinessException("没有相匹配的数据！");
            }
        }

        List<String> lbList = StringPatternUtils.getListByIds(lxjh.getFjhcjlb());

        int order = 1;
        for (String lb : lbList){
            SpcyJcyRzlb jcydjlb = new SpcyJcyRzlb();
            jcydjlb.setId(GetUuIdUtils.ReplaceUuId());
            jcydjlb.setFuserid(userid);
            jcydjlb.setFlxjhid(flxjhid);
            jcydjlb.setFjctz("");
            jcydjlb.setFjcylb(lb);
            jcydjlb.setFxzzt("1"); // 默认选中
            jcydjlb.setCreateTime(new Date());
            jcydjlb.setForder(order);
            lbsList.add(jcydjlb);

            order++;
        }

        if (CollectionUtils.isNotEmpty(lbsList)){
            spcyJcyRzlbService.saveBatch(lbsList);
        }
        return lbsList;
    }

    /**
     * 提交-检查员登记表
     * @param userid
     */
    public void submitJcydjb(String userid, String flxjhid){
        if (StringUtils.isBlank(userid)){
            throw new BusinessException("提交失败，登记表参数为空！");
        }
        if (StringUtils.isBlank(flxjhid)){
            throw new BusinessException("提交失败，参数为空！");
        }
        YcSysUser user = sysUserService.getById(userid);
        if (user == null){
            throw new BusinessException("提交失败，登记表参数不存在！");
        }
        if (StringUtils.isBlank(user.getFsfzh())){
            throw new BusinessException("请填写身份证号！");
        }
        if (StringUtils.isBlank(user.getRealname())){
            throw new BusinessException("请填写姓名！");
        }
        if (StringUtils.isBlank(user.getPhone())){
            throw new BusinessException("请填写手机号码！");
        }
        if (StringUtils.isBlank(user.getEmail())){
            throw new BusinessException("请填写邮箱！");
        }

        /*List<SpcyJcyRzlb> rzlbList = spcyJcyRzlbService.selectLbList(userid, flxjhid, true);
        if (CollectionUtil.isEmpty(rzlbList)){
            throw new BusinessException("请至少选择一项检查员类别！");
        }*/

        SpcyPxCjry cjry = spcyPxCjryService.selectLxCjryByLxjhId(flxjhid, userid);
        if (cjry != null) {
            if (StringUtils.isBlank(cjry.getFdwyj())) {
                throw new BusinessException("请填写单位意见！");
            }

            String sjcjzt = "";
            if (StringUtils.isBlank(cjry.getFsjcjzt()) || cjry.getFsjcjzt().equals(JcydjbConstant.SJCJZT_TXZ)){
                sjcjzt = JcydjbConstant.SJCJZT_YTJ;

            } else if (cjry.getFsjcjzt().equals(JcydjbConstant.SJCJZT_YTJ)) {
                if (StringUtils.isBlank(cjry.getFcfgzwj())){
                    throw new BusinessException("请上传盖章后的文件！");
                }
                sjcjzt = JcydjbConstant.LX_SJCJZT_YWC;

                cjry.setFtjrq(DateConversionUtils.DateToStringYYYYMMDD(new Date()));
                cjry.setFsjshzt(JcyLxjhConstant.JCYLX_CJRY_SJSHZT_WSH);

                String rzlb = "";
                List<SpcyJcyRzlb> rzlbList = spcyJcyRzlbService.selectLbList(userid, flxjhid, true);
                if (CollectionUtil.isNotEmpty(rzlbList)){

                    for (SpcyJcyRzlb jcyRzlb : rzlbList){
                        if (StringUtils.isBlank(rzlb)){
                            rzlb += jcyRzlb.getFjcylb();
                        }else {
                            rzlb += "," + jcyRzlb.getFjcylb();
                        }
                    }
                }
                cjry.setFlxjcylb(rzlb);
            }

            cjry.setFsjcjzt(sjcjzt);
            spcyPxCjryService.updateById(cjry);
        }else {
            throw new BusinessException("提交失败，没有相匹配的数据！");
        }
    }

    /**
     * 将数据采集状态已提交信息修改为填写中
     */
    public void updateSjcjztYtjToTxz(String userid, String flxjhid){
        if (StringUtils.isBlank(userid)){
            throw new BusinessException("请选择已提交的数据！");
        }
        if (StringUtils.isBlank(flxjhid)){
            throw new BusinessException("参数为空！");
        }

        List<String> listByIds = StringPatternUtils.getListByIds(userid);

        SpcyPxCjry cjry = spcyPxCjryService.selectLxCjryByLxjhId(flxjhid, listByIds.get(0));
        if (cjry != null){
            String oldCfwjlj = cjry.getFcfwjlj();

            if (StringUtils.isNotBlank(cjry.getFsjshzt()) && cjry.getFsjshzt().equals(JcyLxjhConstant.JCYLX_CJRY_SJSHZT_SHTG)){
                throw new BusinessException("退回失败，已经审核通过，无法再次退回！");
            }

            cjry.setFsjcjzt(JcydjbConstant.SJCJZT_TXZ);
            cjry.setFcfwjlj("");
            spcyPxCjryService.updateById(cjry);

            if (StringUtils.isNotBlank(oldCfwjlj)) {
                spcyMinioUtils.remove(oldCfwjlj);
            }
        }
    }

    /**
     * 遴选采集人员-退回修改
     */
    public void updateLxUserThxg(String ids, String opinion){
        if (StringUtils.isBlank(ids)){
            throw new BusinessException("请选择已提交的数据！");
        }

        List<String> listByIds = StringPatternUtils.getListByIds(ids);

        List<SpcyPxCjry> cjryList = spcyPxCjryService.listByIds(listByIds);
        if (CollectionUtil.isEmpty(cjryList)){
            return;
        }
        for (SpcyPxCjry cjry : cjryList) {
            String oldCfwjlj = cjry.getFcfwjlj();

            cjry.setFsjshzt(JcyLxjhConstant.JCYLX_CJRY_SJSHZT_THXG);
            cjry.setFsjcjzt(JcydjbConstant.SJCJZT_TXZ);
            cjry.setFcfwjlj("");
            cjry.setFbz(opinion);
            spcyPxCjryService.updateById(cjry);

            if (StringUtils.isNotBlank(oldCfwjlj)) {
                spcyMinioUtils.remove(oldCfwjlj);
            }
        }
    }

    /** 遴选采集人员-审核通过 */
    public void updateLxUserShtg(String ids){
        if (StringUtils.isBlank(ids)){
            throw new BusinessException("请选择已提交的数据！");
        }

        List<String> listByIds = StringPatternUtils.getListByIds(ids);

        if (CollectionUtil.isEmpty(listByIds)){
            return;
        }

        for (String id : listByIds) {
            if (StringUtils.isBlank(id)){
                continue;
            }

            LambdaUpdateWrapper<SpcyPxCjry> updateWrapper = new LambdaUpdateWrapper<>();
            updateWrapper.eq(SpcyPxCjry::getId, id);

            SpcyPxCjry updateCjry = new SpcyPxCjry();
            updateCjry.setFsjshzt(JcyLxjhConstant.JCYLX_CJRY_SJSHZT_SHTG);
            spcyPxCjryService.update(updateCjry, updateWrapper);
        }

        /*List<SpcyPxCjry> cjryList = spcyPxCjryService.listByIds(listByIds);
        if (CollectionUtil.isEmpty(cjryList)){
            return;
        }

        for (SpcyPxCjry cjry : cjryList) {
            cjry.setFsjshzt(JcyLxjhConstant.JCYLX_CJRY_SJSHZT_SHTG);
            spcyPxCjryService.updateById(cjry);
        }*/

    }

    /** 遴选采集人员-审核不通过 */
    public void updateLxUserShbtg(String ids, String opinion){
        if (StringUtils.isBlank(ids)){
            throw new BusinessException("请选择已提交的数据！");
        }

        List<String> listByIds = StringPatternUtils.getListByIds(ids);

        List<SpcyPxCjry> cjryList = spcyPxCjryService.listByIds(listByIds);
        if (CollectionUtil.isEmpty(cjryList)){
            return;
        }
        for (SpcyPxCjry cjry : cjryList) {
            String oldCfwjlj = cjry.getFcfwjlj();

            cjry.setFsjshzt(JcyLxjhConstant.JCYLX_CJRY_SJSHZT_SHBTG);
            cjry.setFsjcjzt(JcydjbConstant.SJCJZT_TXZ);
            cjry.setFcfwjlj("");
            cjry.setFbz(opinion);
            spcyPxCjryService.updateById(cjry);

            if (StringUtils.isNotBlank(oldCfwjlj)) {
                spcyMinioUtils.remove(oldCfwjlj);
            }
        }
    }

    /** 遴选采集人员-设置考核结果 */
    public void updateLxUserKhjg(JcyLxKhjgBo paramsBo){
        if (StringUtils.isBlank(paramsBo.getIds())){
            throw new BusinessException("请选择已提交的数据！");
        }
        if (StringUtils.isBlank(paramsBo.getFkhjg())){
            throw new BusinessException("考核结果参数为空！");
        }

        List<String> listByIds = StringPatternUtils.getListByIds(paramsBo.getIds());

        for (String id : listByIds) {
            LambdaUpdateWrapper<SpcyPxCjry> updateWrapper = new LambdaUpdateWrapper<>();
            updateWrapper.eq(SpcyPxCjry::getId, id);

            SpcyPxCjry cjry = new SpcyPxCjry();
            cjry.setFkhjg(paramsBo.getFkhjg());
            spcyPxCjryService.update(cjry, updateWrapper);
        }
    }

    /**
     * 获取报名人员答卷id
     * @param id 报名人员id
     */
    public Map getCjryDjidByCjryId(String id){
        if (StringUtils.isBlank(id)){
            throw new BusinessException("参数为空!");
        }
        SpcyPxCjry cjry = spcyPxCjryService.getById(id);
        if (cjry == null){
            throw new BusinessException("没有相匹配的数据！");
        }

        String djid = "";
        if (StringUtils.isNotBlank(cjry.getFuserid()) && StringUtils.isNotBlank(cjry.getFpxjbxxid())) {
            List<SpcyPxDjjbxx> userDjList = spcyPxDjjbxxService.list(new LambdaQueryWrapper<SpcyPxDjjbxx>()
                    .eq(SpcyPxDjjbxx::getFuserid, cjry.getFuserid())
                    .eq(SpcyPxDjjbxx::getFpxjbxxid, cjry.getFpxjbxxid()));
            if (CollectionUtil.isNotEmpty(userDjList)) {
                djid = userDjList.get(0).getId();
            }
        }

        Map result = new HashMap();
        result.put("id", djid);
        return result;
    }

    /**
     * 下载检查员登记表-根据登记表id
     * @param cjryid 遴选参加人员id
     */
    public void downloadDjbFile(String cjryid, HttpServletResponse response){
        if (StringUtils.isBlank(cjryid)){
            throw new BusinessException("参数为空！");
        }
        SpcyPxCjry jcydjb = spcyPxCjryService.getById(cjryid);
        if (jcydjb == null){
            throw new BusinessException("没有相匹配的数据！");
        }
        if (StringUtils.isBlank(jcydjb.getFuserid())){
            throw new BusinessException("人员不存在！");
        }
        YcSysUser user = sysUserService.getById(jcydjb.getFuserid());
        if (user == null){
            throw new BusinessException("没有相匹配的数据！");
        }
        JcyLxUserVo lxUserVo = new JcyLxUserVo();
        BeanUtil.copyProperties(user, lxUserVo);
        lxUserVo.setFtjrq(jcydjb.getFtjrq());
        lxUserVo.setFpxjbxxid(jcydjb.getFpxjbxxid());
        lxUserVo.setFsjcjzt(jcydjb.getFsjcjzt());
        lxUserVo.setFdwyj(jcydjb.getFdwyj());
//        lxUserVo.setFcfwjlj(jcydjb.getFcfwjlj());
//        lxUserVo.setFcfgzwj(jcydjb.getFcfgzwj());

        boolean isExistGzwj = false;
        if (StringUtils.isNotBlank(jcydjb.getFcfgzwj())){
            isExistGzwj = true;

            List<SpcySqsxWjjl> wjjlList = spcySqsxWjjlService.list(new LambdaQueryWrapper<SpcySqsxWjjl>()
                    .eq(SpcySqsxWjjl::getFpid, jcydjb.getId())
                    .eq(SpcySqsxWjjl::getFwjlx1, LogConstant.LOGS_JCY_LXTJBGZWJ));
            if (CollectionUtil.isNotEmpty(wjjlList) && StringUtils.isNotBlank(wjjlList.get(0).getFcflj())) {
                if (localFileUploadUtils.isEnableMinioWjjlFile()) {
                    spcyMinioUtils.download(wjjlList.get(0).getFcflj(), response);
                }else {
                    localFileUploadUtils.ejzLocalFileByZdyFile(new File(localFileUploadUtils.getZdyFileAbsUrl(wjjlList.get(0).getFcflj())), response);
                }
            }
        }

        boolean isExistWjjl = false;
        if (StringUtils.isNotBlank(jcydjb.getFcfwjlj())){
            isExistWjjl = true;
        }

        if (isExistWjjl && !isExistGzwj) {
            spcyMinioUtils.download(jcydjb.getFcfwjlj(), response);
        }

        if (!isExistWjjl && !isExistGzwj) {


            String orgUrl = "";
            String destWordUrl = ""; // word保存路径
            String destPdfUrl = ""; // pdf保存路径
            String wjlx = Util.getWjHz(orgUrl); // 获取文件路径的 文件类型
            String formatType = BusinessConstant.getWordFormatType(wjlx); // word替换格式

            destWordUrl = localFileUploadUtils.getTempFileRootUrl() + "/";
            destPdfUrl = destWordUrl;
            destWordUrl += GetUuIdUtils.ReplaceUuId() + wjlx;
            destPdfUrl += GetUuIdUtils.ReplaceUuId() + ".pdf";

            boolean flag = false;
            if (!newTemplateMethod){
                orgUrl = businessConstant.UPLOAD_FILE_ROOT + "/" + JcydjbConstant.JCYDLX_TEMPLATE_NAME;

                Map<String, String> templateField = this.getTemplateField(lxUserVo);
                flag = InsertAndOutWordUtils.wordTextSubstitutionTwo(orgUrl, destWordUrl, formatType, templateField);// word关键字替换文本,并生成新文件

            }else {
                orgUrl = businessConstant.UPLOAD_FILE_ROOT + "/" + JcydjbConstant.JCYDLX_TEMPLATE_NAME2;

                HashMap<String, Object> templateField = this.getTemplateField2(lxUserVo);

                // 获取用户照片地址
                SpcySqsxWjjl photoWjjl = spcySqsxWjjlService.downMyUserPhoto(jcydjb.getFuserid(), null);
                if (photoWjjl == null){
                    throw new BusinessException("没有相关签名！");
                }
                File file = null;
                if (localFileUploadUtils.isEnableMinioWjjlFile()) {
                    InputStream inputStream = spcyMinioUtils.getObject(photoWjjl.getFcflj());
                    if (inputStream == null) {
                        throw new BusinessException("没有相关文件流！");
                    }
                    file = localFileUploadUtils.asFile(inputStream, Util.getWjHz(photoWjjl.getFcflj()));
                }else {
                    file = new File(localFileUploadUtils.getZdyFileAbsUrl(photoWjjl.getFcflj()));
                }

                try {
                    templateField.put("photo", Pictures.ofStream(new FileInputStream(file.getAbsoluteFile()), PictureType.JPEG)
                            .size(155, 200).create());
                } catch (FileNotFoundException e) {
                    e.printStackTrace();
                }
                flag = WordDocxReplaceUtils.docxReplaceFlag(orgUrl, destWordUrl, templateField);
            }

            if (flag) {
                wordPdfUtils.wordToPdf2(destWordUrl, destPdfUrl);

                localFileUploadUtils.ejzLocalFileByZdyFile(new File(destPdfUrl), response);
            }
        }
    }

    /**
     * 下载检查员登记表-根据登记表id
     * @param userid 用户id
     * @param flxjhid 遴选计划id
     */
    public void downloadDjbFile(String userid, String flxjhid, HttpServletResponse response){
        if (StringUtils.isBlank(userid)){
            throw new BusinessException("下载失败，登记参数为空！");
        }
        if (StringUtils.isBlank(flxjhid)){
            throw new BusinessException("下载失败，参数为空！");
        }
        JcyLxUserVo lxUserVo = new JcyLxUserVo();
        YcSysUser user = sysUserService.getById(userid);
        if (user == null){
            throw new BusinessException("没有相匹配的数据！");
        }
        SpcyPxCjry jcydjb = spcyPxCjryService.selectLxCjryByLxjhId(flxjhid, userid);
        if (jcydjb == null){
            throw new BusinessException("查无对应数据！");
        }
        BeanUtil.copyProperties(user, lxUserVo);
        lxUserVo.setFtjrq(jcydjb.getFtjrq());
        lxUserVo.setFpxjbxxid(jcydjb.getFpxjbxxid());
        lxUserVo.setFsjcjzt(jcydjb.getFsjcjzt());
        lxUserVo.setFdwyj(jcydjb.getFdwyj());
        lxUserVo.setFcfwjlj(jcydjb.getFcfwjlj());

        if (StringUtils.isNotBlank(jcydjb.getFsjcjzt()) && jcydjb.getFsjcjzt().equals(JcydjbConstant.SJCJZT_TXZ)){
            throw new BusinessException("下载失败！当前数据还没有提交无法下载相关文件！");
        }

        boolean isExistWjjl = false;
        if (StringUtils.isNotBlank(jcydjb.getFcfwjlj())){
            isExistWjjl = true;
        }

        if (!isExistWjjl) {

            String orgUrl = JcydjbConstant.JCYDLX_TEMPLATE_NAME;
            String destWordUrl = ""; // word保存路径
            String destPdfUrl = ""; // pdf保存路径
            String wjlx = Util.getWjHz(orgUrl); // 获取文件路径的 文件类型
            String formatType = BusinessConstant.getWordFormatType(wjlx); // word替换格式

            destWordUrl = localFileUploadUtils.getTempFileRootUrl() + "/";
            destPdfUrl = destWordUrl;
            destWordUrl += GetUuIdUtils.ReplaceUuId() + wjlx;
            destPdfUrl += GetUuIdUtils.ReplaceUuId() + ".pdf";

            boolean flag = false;
            if (!newTemplateMethod) {
                orgUrl = businessConstant.UPLOAD_FILE_ROOT + "/" + JcydjbConstant.JCYDLX_TEMPLATE_NAME;
                Map<String, String> templateField = this.getTemplateField(lxUserVo);

                flag = InsertAndOutWordUtils.wordTextSubstitutionTwo(orgUrl, destWordUrl, formatType, templateField);// word关键字替换文本,并生成新文件

            }else {
                orgUrl = businessConstant.UPLOAD_FILE_ROOT + "/" + JcydjbConstant.JCYDLX_TEMPLATE_NAME2;
                HashMap<String, Object> templateField = this.getTemplateField2(lxUserVo);

                // 获取用户照片地址
                SpcySqsxWjjl photoWjjl = spcySqsxWjjlService.downMyUserPhoto(userid, null);
                if (photoWjjl == null){
                    throw new BusinessException("没有相关签名！");
                }

                File file = null;
                if (localFileUploadUtils.isEnableMinioWjjlFile()){
                    InputStream inputStream = spcyMinioUtils.getObject(photoWjjl.getFcflj());
                    if (inputStream == null){
                        throw new BusinessException("没有相关文件流！");
                    }
                    file = localFileUploadUtils.asFile(inputStream, Util.getWjHz(photoWjjl.getFcflj()));
                }else {
                    file = new File(localFileUploadUtils.getZdyFileAbsUrl(photoWjjl.getFcflj()));
                }

                try {
                    templateField.put("photo", Pictures.ofStream(new FileInputStream(file.getAbsoluteFile()), PictureType.JPEG)
                            .size(155, 200).create());
                } catch (FileNotFoundException e) {
                    e.printStackTrace();
                }

                flag = WordDocxReplaceUtils.docxReplaceFlag(orgUrl, destWordUrl, templateField);
            }

            if (flag) {
                wordPdfUtils.wordToPdf2(destWordUrl, destPdfUrl);

                String cfwjlj = "/"+SpcyConstant.JCY_LXDJB_FILE_BASE_URL+"/"+ DateConversionUtils.DateToYear(new Date()) +"/"+ GetUuIdUtils.ReplaceUuId() + ".pdf";

                if (localFileUploadUtils.isEnableMinioWjjlFile()){
                    spcyMinioUtils.putFile(cfwjlj, new File(destPdfUrl), ".pdf");
                }else {
                    FileCopyUtils.copyFile(destPdfUrl, localFileUploadUtils.getZdyFileAbsUrl(cfwjlj));
                }
                jcydjb.setFcfwjlj(cfwjlj);
                spcyPxCjryService.updateById(jcydjb);

                localFileUploadUtils.ejzLocalFileByZdyFile(new File(destPdfUrl), response);
            }
        }

        if (isExistWjjl) {
            if (localFileUploadUtils.isEnableMinioWjjlFile()) {
                spcyMinioUtils.download(jcydjb.getFcfwjlj(), response);
            }else {
                localFileUploadUtils.ejzLocalFileByZdyFile(new File(localFileUploadUtils.getZdyFileAbsUrl(jcydjb.getFcfwjlj())), response);
            }
        }
    }

    public void cxxzwj(String userid, String flxjhid, boolean templateFlag, HttpServletResponse response){
        if (StringUtils.isBlank(userid)){
            throw new BusinessException("下载失败，登记参数为空！");
        }
        if (StringUtils.isBlank(flxjhid)){
            throw new BusinessException("下载失败，参数为空！");
        }
        JcyLxUserVo lxUserVo = new JcyLxUserVo();
        YcSysUser user = sysUserService.getById(userid);
        if (user == null){
            throw new BusinessException("没有相匹配的数据！");
        }
        SpcyPxCjry jcydjb = spcyPxCjryService.selectLxCjryByLxjhId(flxjhid, userid);
        if (jcydjb == null){
            throw new BusinessException("查无对应数据！");
        }
        BeanUtil.copyProperties(user, lxUserVo);
        lxUserVo.setFtjrq(jcydjb.getFtjrq());
        lxUserVo.setFpxjbxxid(jcydjb.getFpxjbxxid());
        lxUserVo.setFsjcjzt(jcydjb.getFsjcjzt());
        lxUserVo.setFdwyj(jcydjb.getFdwyj());
        lxUserVo.setFcfwjlj(jcydjb.getFcfwjlj());

        if (StringUtils.isNotBlank(jcydjb.getFsjcjzt()) && jcydjb.getFsjcjzt().equals(JcydjbConstant.SJCJZT_TXZ)){
            throw new BusinessException("下载失败！当前数据还没有提交无法下载相关文件！");
        }

        String orgUrl = JcydjbConstant.JCYDLX_TEMPLATE_NAME;
        String destWordUrl = ""; // word保存路径
        String destPdfUrl = ""; // pdf保存路径
        String wjlx = Util.getWjHz(orgUrl); // 获取文件路径的 文件类型
        String formatType = BusinessConstant.getWordFormatType(wjlx); // word替换格式

        destWordUrl = localFileUploadUtils.getTempFileRootUrl() + "/";
        destPdfUrl = destWordUrl;
        destWordUrl += GetUuIdUtils.ReplaceUuId() + wjlx;
        destPdfUrl += GetUuIdUtils.ReplaceUuId() + ".pdf";

        boolean flag = false;
        if (!templateFlag) {
            orgUrl = businessConstant.UPLOAD_FILE_ROOT + "/" + JcydjbConstant.JCYDLX_TEMPLATE_NAME;
             Map<String, String> templateField = this.getTemplateField(lxUserVo);

            flag = InsertAndOutWordUtils.wordTextSubstitutionTwo(orgUrl, destWordUrl, formatType, templateField);// word关键字替换文本,并生成新文件

        }else {
            orgUrl = businessConstant.UPLOAD_FILE_ROOT + "/" + JcydjbConstant.JCYDLX_TEMPLATE_NAME2;
            HashMap<String, Object> templateField = this.getTemplateField2(lxUserVo);

            // 获取用户照片地址
//            String photoUrl = spcyMyInfoService.genUserPhotoLink(userid);

            SpcySqsxWjjl photoWjjl = spcySqsxWjjlService.downMyUserPhoto(userid, null);
            if (photoWjjl == null){
                throw new BusinessException("没有相关签名！");
            }
            InputStream inputStream = spcyMinioUtils.getObject(photoWjjl.getFcflj());
            if (inputStream == null){
                throw new BusinessException("没有相关文件流！");
            }
            File file = localFileUploadUtils.asFile(inputStream, Util.getWjHz(photoWjjl.getFcflj()));

            /*
            // 网络图片(注意网络耗时对系统可能的性能影响)
            BufferedImage bufferImage = null;
            try {
                bufferImage = ImageIO.read(file);
            } catch (IOException e) {
                log.error("下载推荐表文件失败！");
            }
            templateField.put("photo", Pictures.ofBufferedImage(bufferImage, com.deepoove.poi.data.PictureType.JPEG)
                    .size(155,200).create());*/

            try {
                templateField.put("photo", Pictures.ofStream(new FileInputStream(file.getAbsoluteFile()), PictureType.JPEG)
                        .size(155, 200).create());
            } catch (FileNotFoundException e) {
                e.printStackTrace();
            }
            flag = WordDocxReplaceUtils.docxReplaceFlag(orgUrl, destWordUrl, templateField);
        }

        if (flag) {
            wordPdfUtils.wordToPdf2(destWordUrl, destPdfUrl);

            localFileUploadUtils.ejzLocalFileByZdyFile(new File(destPdfUrl), response);
        }


    }

    private HashMap<String, Object> getTemplateField2(JcyLxUserVo jcydjb){

        HashMap<String, Object> objectMap = new HashMap<>();

        if (jcydjb == null){
            throw new BusinessException("当前数据不存在！请刷新重试！");
        }

        String defaultParam = "无";
        String csny = defaultParam; // 出生年月
        String xb = defaultParam; // 性别
        HashMap<String, Object> map = ObjectCopyUtils.objectToMap2(jcydjb);
        objectMap.putAll(map);

        // 出生年月
        if (jcydjb.getBirthday() != null){
            csny = DateConversionUtils.DateToMonth(jcydjb.getBirthday());
        }

        // 性别
        if (jcydjb.getSex() != null){
            xb = String.valueOf(jcydjb.getSex());
            if (xb.equals("1")){
                xb = "男";
            }else {
                xb = "女";
            }
        }

        objectMap.put("csny",csny);
        objectMap.put("xb",xb);


        String nowTime = "无"; // 当前时间
        String nowYear = "无"; // 当前年份

        nowTime = DateConversionUtils.DateToYMDString(DateConversionUtils.DateToString(new Date())); // 当前时间
        objectMap.put("nowTime", nowTime);

        // 当前年份
        if (StringUtils.isBlank(jcydjb.getFtjrq())){
            nowYear = DateConversionUtils.DateToYear(new Date());
        }else {
            nowYear = DateConversionUtils.DateToYear(DateConversionUtils.convertStringToDateYear(jcydjb.getFtjrq()));
        }
        objectMap.put("nowYear", nowYear);

        StringBuffer lb = new StringBuffer();
        List<SpcyJcyRzlb> lbList = spcyJcyRzlbService.selectLbList(jcydjb.getId(), jcydjb.getFpxjbxxid(), true);
        if (CollectionUtils.isNotEmpty(lbList)){
            int count = 1;
            for (SpcyJcyRzlb jcydjlb : lbList){
                if (count>1){
//                    lb.append("\n");
                    lb.append(",");
                }
                lb.append(jcydjlb.getFjcylb());
//                lb.append("；特长：").append(Optional.ofNullable(jcydjlb.getFjctz()).orElseGet(()->defaultParam));
//                lb.append("；");
                count++;
            }
        }

        StringBuffer gzjl = new StringBuffer();
        List<SysUserGzjl> spcyRsJcydjgzjls = sysUserGzjlService.list(new LambdaQueryWrapper<SysUserGzjl>()
                .eq(SysUserGzjl::getFuserid, jcydjb.getId())
                .orderByAsc(SysUserGzjl::getCreateTime));
        if (CollectionUtils.isNotEmpty(spcyRsJcydjgzjls)){
            int count = 1;
            for (SysUserGzjl jcydjgzjl : spcyRsJcydjgzjls){

                if (count > 1){
                    gzjl.append("\n");
                }

                boolean kssj = true;
                if (jcydjgzjl.getFgzkssj() != null){
                    gzjl.append(jcydjgzjl.getFgzkssj());
                }else {
                    kssj = false;
                    gzjl.append(defaultParam);
                }

                if (StringUtils.isNotBlank(jcydjgzjl.getFgzjssj())){
                    if (jcydjgzjl.getFgzjssj().contains(JcydjbConstant.GZJL_END_TIME_ZJ)){
                        gzjl.append(JcydjbConstant.GZJL_END_TIME_ZJ);
                    }else {
                        gzjl.append("至");
                        gzjl.append(jcydjgzjl.getFgzjssj());
                    }
                }else {
                    if (kssj){
                        gzjl.append("至");
                        gzjl.append(defaultParam);
                    }
                }

                gzjl.append(" ");
                gzjl.append(Optional.ofNullable(jcydjgzjl.getFgzdw()).orElseGet(()->defaultParam));
                gzjl.append(" ");
                gzjl.append(Optional.ofNullable(jcydjgzjl.getFcsgz()).orElseGet(()->defaultParam));
                gzjl.append(" ");
                gzjl.append(Optional.ofNullable(jcydjgzjl.getFzw()).orElseGet(()->defaultParam));
                gzjl.append("；");

                count++;
            }
        }else {
            gzjl.append(defaultParam);
        }

        StringBuffer wz = new StringBuffer();
        List<SysUserFbwz> wzList = sysUserFbwzService.list(new LambdaQueryWrapper<SysUserFbwz>()
                .eq(SysUserFbwz::getFuserid, jcydjb.getId())
                .orderByAsc(SysUserFbwz::getCreateTime));
        if (CollectionUtils.isNotEmpty(wzList)){
            int count = 1;
            for (SysUserFbwz jcydjfbwz : wzList){

                if (count > 1){
                    wz.append("\n");
                }

                if (jcydjfbwz.getFfbsj() != null){
                    wz.append(DateConversionUtils.DateToMonth(jcydjfbwz.getFfbsj()));
                }else {
                    wz.append(defaultParam);
                }

                wz.append(" ");
                wz.append(Optional.ofNullable(jcydjfbwz.getFqkmc()).orElseGet(()->defaultParam));
                wz.append(" ");
                wz.append(Optional.ofNullable(jcydjfbwz.getFwzmc()).orElseGet(()->defaultParam));
                wz.append("；");

                count++;
            }
        }else {
            wz.append(defaultParam);
        }

        StringBuffer pxjl = new StringBuffer();
        List<SysUserPxjl> pxjlList = sysUserPxjlService.list(new LambdaQueryWrapper<SysUserPxjl>()
                .eq(SysUserPxjl::getFuserid, jcydjb.getId())
                .orderByAsc(SysUserPxjl::getCreateTime));
        if (CollectionUtils.isNotEmpty(pxjlList)){
            int count = 1;
            for (SysUserPxjl nowPxjl : pxjlList) {

                if (count > 1) {
                    pxjl.append("\n");
                }

                boolean kssj = true;
                if (nowPxjl.getFpxkssj() != null){
                    pxjl.append(DateConversionUtils.DateToStringYYYYMMDD(nowPxjl.getFpxkssj()));
                }else {
                    kssj = false;
                    pxjl.append(defaultParam);
                }

                if (kssj){
                    pxjl.append("至");
                }

                if (nowPxjl.getFpxjssj() != null){
                    pxjl.append(DateConversionUtils.DateToStringYYYYMMDD(nowPxjl.getFpxjssj()));
                }else {
                    pxjl.append(defaultParam);
                }

                pxjl.append(" ");
                pxjl.append(Optional.ofNullable(nowPxjl.getFpxmc()).orElseGet(()->defaultParam));
                pxjl.append(" ");
                pxjl.append(Optional.ofNullable(nowPxjl.getFpxdd()).orElseGet(()->defaultParam));
                pxjl.append(" ");
                pxjl.append(Optional.ofNullable(nowPxjl.getFpxxs()).orElseGet(()->defaultParam));
                pxjl.append("；");

                count++;

            }
        }else {
            pxjl.append(defaultParam);
        }

        objectMap.put("lb", lb.toString());
        objectMap.put("gzjl", gzjl.toString());
        objectMap.put("wz", wz.toString());
        objectMap.put("pxjl", pxjl.toString());
        return objectMap;
    }

    /**
     * 获取检查员登记表-字段模板
     * @return
     */
    private Map<String,String> getTemplateField(JcyLxUserVo jcydjb){

        Map<String,String> objectMap = new HashMap<>();

        if (jcydjb == null){
            throw new BusinessException("当前数据不存在！请刷新重试！");
        }

        String defaultParam = "无";
        String csny = defaultParam; // 出生年月
        String xb = defaultParam; // 性别
        Map<String, String> map = this.objectToMap(jcydjb);
        objectMap.putAll(map);

        // 出生年月
        if (jcydjb.getBirthday() != null){
            csny = DateConversionUtils.DateToMonth(jcydjb.getBirthday());
        }

        // 性别
        if (jcydjb.getSex() != null){
            xb = String.valueOf(jcydjb.getSex());
            if (xb.equals("1")){
                xb = "男";
            }else {
                xb = "女";
            }
        }

        objectMap.put("${data.csny}",csny);
        objectMap.put("${data.xb}",xb);


        String nowTime = "无"; // 当前时间
        String nowYear = "无"; // 当前年份

        nowTime = DateConversionUtils.DateToYMDString(DateConversionUtils.DateToString(new Date())); // 当前时间
        objectMap.put("${data.nowTime}", nowTime);

        // 当前年份
        if (StringUtils.isBlank(jcydjb.getFtjrq())){
            nowYear = DateConversionUtils.DateToYear(new Date());
        }else {
            nowYear = DateConversionUtils.DateToYear(DateConversionUtils.convertStringToDateYear(jcydjb.getFtjrq()));
        }
        objectMap.put("nowYear", nowYear);

        StringBuffer lb = new StringBuffer();
        List<SpcyJcyRzlb> lbList = spcyJcyRzlbService.selectLbList(jcydjb.getId(), jcydjb.getFpxjbxxid(), true);
        if (CollectionUtils.isNotEmpty(lbList)){
            int count = 1;
            for (SpcyJcyRzlb jcydjlb : lbList){
                if (count>1){
//                    lb.append("\n");
                    lb.append(",");
                }
                lb.append(jcydjlb.getFjcylb());
//                lb.append("；特长：").append(Optional.ofNullable(jcydjlb.getFjctz()).orElseGet(()->defaultParam));
//                lb.append("；");
                count++;
            }
        }

        StringBuffer gzjl = new StringBuffer();
        List<SysUserGzjl> spcyRsJcydjgzjls = sysUserGzjlService.list(new LambdaQueryWrapper<SysUserGzjl>()
                .eq(SysUserGzjl::getFuserid, jcydjb.getId())
                .orderByAsc(SysUserGzjl::getCreateTime));
        if (CollectionUtils.isNotEmpty(spcyRsJcydjgzjls)){
            int count = 1;
            for (SysUserGzjl jcydjgzjl : spcyRsJcydjgzjls){

                if (count > 1){
                    gzjl.append("\n");
                }

                boolean kssj = true;
                if (jcydjgzjl.getFgzkssj() != null){
                    gzjl.append(jcydjgzjl.getFgzkssj());
                }else {
                    kssj = false;
                    gzjl.append(defaultParam);
                }

                if (StringUtils.isNotBlank(jcydjgzjl.getFgzjssj())){
                    if (jcydjgzjl.getFgzjssj().contains(JcydjbConstant.GZJL_END_TIME_ZJ)){
                        gzjl.append(JcydjbConstant.GZJL_END_TIME_ZJ);
                    }else {
                        gzjl.append("至");
                        gzjl.append(jcydjgzjl.getFgzjssj());
                    }
                }else {
                    if (kssj){
                        gzjl.append("至");
                        gzjl.append(defaultParam);
                    }
                }

                gzjl.append("\t");
                gzjl.append(Optional.ofNullable(jcydjgzjl.getFgzdw()).orElseGet(()->defaultParam));
                gzjl.append("\t");
                gzjl.append(Optional.ofNullable(jcydjgzjl.getFcsgz()).orElseGet(()->defaultParam));
                gzjl.append("\t");
                gzjl.append(Optional.ofNullable(jcydjgzjl.getFzw()).orElseGet(()->defaultParam));
                gzjl.append("；");

                count++;
            }
        }else {
            gzjl.append(defaultParam);
        }

        StringBuffer wz = new StringBuffer();
        List<SysUserFbwz> wzList = sysUserFbwzService.list(new LambdaQueryWrapper<SysUserFbwz>()
                .eq(SysUserFbwz::getFuserid, jcydjb.getId())
                .orderByAsc(SysUserFbwz::getCreateTime));
        if (CollectionUtils.isNotEmpty(wzList)){
            int count = 1;
            for (SysUserFbwz jcydjfbwz : wzList){

                if (count > 1){
                    wz.append("\n");
                }

                if (jcydjfbwz.getFfbsj() != null){
                    wz.append(DateConversionUtils.DateToMonth(jcydjfbwz.getFfbsj()));
                }else {
                    wz.append(defaultParam);
                }

                wz.append("\t");
                wz.append(Optional.ofNullable(jcydjfbwz.getFqkmc()).orElseGet(()->defaultParam));
                wz.append("\t");
                wz.append(Optional.ofNullable(jcydjfbwz.getFwzmc()).orElseGet(()->defaultParam));
                wz.append("；");

                count++;
            }
        }else {
            wz.append(defaultParam);
        }

        StringBuffer pxjl = new StringBuffer();
        List<SysUserPxjl> pxjlList = sysUserPxjlService.list(new LambdaQueryWrapper<SysUserPxjl>()
                .eq(SysUserPxjl::getFuserid, jcydjb.getId())
                .orderByAsc(SysUserPxjl::getCreateTime));
        if (CollectionUtils.isNotEmpty(pxjlList)){
            int count = 1;
            for (SysUserPxjl nowPxjl : pxjlList) {

                if (count > 1) {
                    pxjl.append("\n");
                }

                boolean kssj = true;
                if (nowPxjl.getFpxkssj() != null){
                    pxjl.append(DateConversionUtils.DateToStringYYYYMMDD(nowPxjl.getFpxkssj()));
                }else {
                    kssj = false;
                    pxjl.append(defaultParam);
                }

                if (kssj){
                    pxjl.append("至");
                }

                if (nowPxjl.getFpxjssj() != null){
                    pxjl.append(DateConversionUtils.DateToStringYYYYMMDD(nowPxjl.getFpxjssj()));
                }else {
                    pxjl.append(defaultParam);
                }

                pxjl.append("\t");
                pxjl.append(Optional.ofNullable(nowPxjl.getFpxmc()).orElseGet(()->defaultParam));
                pxjl.append("\t");
                pxjl.append(Optional.ofNullable(nowPxjl.getFpxdd()).orElseGet(()->defaultParam));
                pxjl.append("\t");
                pxjl.append(Optional.ofNullable(nowPxjl.getFpxxs()).orElseGet(()->defaultParam));
                pxjl.append("；");

                count++;

            }
        }else {
            pxjl.append(defaultParam);
        }

        objectMap.put("${data.lb}", lb.toString());
        objectMap.put("${data.gzjl}", gzjl.toString());
        objectMap.put("${data.wz}", wz.toString());
        objectMap.put("${data.pxjl}", pxjl.toString());
        return objectMap;
    }

    /**
     * 将对象转成Map对象-模板字段
     * @param object
     * @return
     */
    private static Map<String,String> objectToMap(Object object) {
        Map<String,String> dataMap = new HashMap<>();
        BeanMap beanMap = BeanMap.create(object);
        for (Object key : beanMap.keySet()) {
            String k = "${data."+key+"}";
            if (beanMap.get(key) != null){
                dataMap.put(k,beanMap.get(key).toString());
            }else {
                dataMap.put(k,"无");
            }
        }
        return dataMap;
    }

    /**
     * 同步生成遴选通过的人员-检查员账号
     */
    @Async(value = "asyncNormalTask")
    public void syncGenLxUserAccount(String flxjhid){
        // 遴选审核通过并考核通过
        List<SpcyPxCjry> lxUserList = spcyPxCjryService.selectLxtgCjryList(flxjhid);
        if (CollectionUtil.isEmpty(lxUserList)){
            return;
        }

        // 更新最终采集人数
        SpcyPxJbxx lxjh = spcyPxJbxxService.getById(flxjhid);
        if (lxjh != null){
            lxjh.setFsjcjrs(lxUserList.size());
            spcyPxJbxxService.updateById(lxjh);
        }

        /** 生成对应的检查员身份及账号 */
        for (SpcyPxCjry cjry : lxUserList){
            YcSysUser nowUser = sysUserService.getById(cjry.getFuserid());

            String sfsqzh = "否";
            if (StringUtils.isBlank(nowUser.getOrgId())) {
                YcSysUser user = sysUserService.genJcyUserAccount(nowUser, nowUser.getId(), sysUserService.getUuidAccount(nowUser.getRealname(), nowUser.getFsfzh()));
                sysUserService.updateById(user);
                sysUserService.genJcyUserDeptGx(nowUser.getId());

                sfsqzh = "是";
            }
            sysUserService.genJcyUserRoleGx(nowUser.getId());
            sysUserService.genJcyUserJobGx(nowUser.getId());

            List<SpcyJcyRzlb> rzlbList = spcyJcyRzlbService.selectLbList(nowUser.getId(), flxjhid, true);

            for (SpcyJcyRzlb lb : rzlbList) {
                String xllx = SpcyConstant.getJcyXllxByJcylb(lb.getFjcylb());
                String jcylb = JcydjbConstant.getJcylbByJcyxl(lb.getFjcylb());
//                String jcyxl = JcydjbConstant.getJcyxlByJcyLb(lb.getFjcylb());
                String jcyxl = JcydjbConstant.getJcyxlByJcyLb2(lb.getFjcylb());

                /** 验证改账号是否绑定改类别下的检查员 */
                JcyExistLbBo existLbBo = spcyRsHcyService.verifyLbJcyIsExistList(jcylb, jcyxl, nowUser.getId());
                String isExistJcy = existLbBo.getSfcz();
                if (isExistJcy.equals("否")) {
                    String newJcyid = GetUuIdUtils.ReplaceUuId();
                    spcyRsHcyService.initNewLxLbJcy(newJcyid,nowUser.getId(), xllx, jcylb, jcyxl, SpcyConstant.HCY_SSK_YB, lb.getFjctz(), lxjh.getFfwbh());
                    spcyRsJcysfbgjlService.initLxJcysgbgjl(nowUser.getId(), newJcyid, jcylb, jcyxl, SpcyConstant.HCY_SSK_YB, lb.getFjctz(), lxjh.getId(), lxjh.getFfwbh(), sfsqzh);
                }else {
                    /*SpcyRsHcy updateJcy = existLbBo.getJcy();
                    if (updateJcy != null){
                        // 当前检查员身份-注销
                        if (StringUtils.isNotBlank(updateJcy.getFstate()) && updateJcy.getFstate().equals(SpcyCommonConstant.JCY_STATE_ZX)) {
                            // 为预备检查员
                            if (StringUtils.isNotBlank(updateJcy.getFssk()) && updateJcy.getFssk().equals(SpcyConstant.HCY_SSK_YB)) {
                                updateJcy.setFstate(SpcyCommonConstant.JCY_STATE_YX);
                                spcyRsHcyService.updateById(updateJcy);
                            }
                        }
                    }*/
                }
            }
        }

    }

    /**
     * 剔除已经生成遴选的人员
     */
    @Async(value = "asyncNormalTask")
    public void cancelSyncGenLxUserAccount(String flxjhid){
        // 遴选审核通过并考核通过
        List<SpcyPxCjry> lxUserList = spcyPxCjryService.selectLxtgCjryList(flxjhid);
        if (CollectionUtil.isEmpty(lxUserList)){
            return;
        }

        /** 生成对应的检查员身份及账号 */
        for (SpcyPxCjry cjry : lxUserList){
            YcSysUser nowUser = sysUserService.getById(cjry.getFuserid());
            if (nowUser == null){
                continue;
            }

            // 身份变更记录
            List<SpcyRsJcysfbgjl> sfbgjlList = spcyRsJcysfbgjlService.list(new LambdaQueryWrapper<SpcyRsJcysfbgjl>()
                    .eq(SpcyRsJcysfbgjl::getFuserid, nowUser.getId())
                    .eq(SpcyRsJcysfbgjl::getFpid, flxjhid));
            if (CollectionUtil.isNotEmpty(sfbgjlList)){
                for (SpcyRsJcysfbgjl bgjl : sfbgjlList){
                    if (StringUtils.isNotBlank(bgjl.getFsfsqzh()) && bgjl.getFsfsqzh().equals("是")) {
                        YcSysUser updateUser = sysUserService.cancelGenJcyUserAccount(nowUser);
                        sysUserService.updateById(updateUser);

                        sysUserService.deleteJcyUserDeptGx(nowUser.getId());
                        sysUserService.deleteJcyUserRoleGx(nowUser.getId());
                        sysUserService.deleteJcyUserJobGx(nowUser.getId());
                    }

                    spcyRsHcyService.removeById(bgjl.getFjcyid());
                    spcyRsJcysfbgjlService.removeById(bgjl.getId());
                }
            }
        }
    }

    /**
     * 后哦亲同步签到场次-对应的签到人数数量
     */
    public int getSyncQdcsCjryNumber(String flxjhid){
        return spcyPxCjryService.selectShztCjryList(flxjhid, JcyLxjhConstant.JCYLX_CJRY_SJSHZT_SHTG).size();
    }

    /**
     * 推荐表盖章文件上传-
     */
    public SpcyPxCjry getUploadtjbgzFile(String flxjhid, String userid){
        SpcyPxCjry cjry = spcyPxCjryService.selectLxCjryByLxjhId(flxjhid, userid);
        if (cjry == null){
            throw new BusinessException("上传失败，没有相匹配的人员！");
        }

        return cjry;
    }

    /**
     * 推荐表盖章文件上传-更新附件路径
     */
    public void updateUploadtjbgzFile(SpcyPxCjry cjry,String fcfgzwj){
        if (cjry != null && StringUtils.isNotBlank(fcfgzwj)){
            cjry.setFcfgzwj(fcfgzwj);
            spcyPxCjryService.updateById(cjry);
        }
    }

    /**
     * 组合查询条件
     * @param state 0: 待审核；1：审核通过；2：审核不通过；3：人员汇总; 4: 人员考核列表; 5: 最终确认名单
     */
    public JcyLxUserVo ZhQueryTj(JcyLxUserVo query, int state){

        if (state == 0) {
            query.setFsjshzt(JcyLxjhConstant.JCYLX_CJRY_SJSHZT_WSH);
            query.setFsjcjzt(JcydjbConstant.LX_SJCJZT_YWC);

        }else if (state == 1){
            query.setFsjshzt(JcyLxjhConstant.JCYLX_CJRY_SJSHZT_SHTG);

        }else if (state == 2){
            query.setFsjshzt(JcyLxjhConstant.JCYLX_CJRY_SJSHZT_SHBTG);

        }else if (state == 3){
            query.setRyhzzt(JcyLxjhConstant.JCYLX_CJRY_SJSHZT_WSH);

        }else if (state == 4){
            query.setFsjshzt(JcyLxjhConstant.JCYLX_CJRY_SJSHZT_SHTG);

        }else if (state == 5){
            query.setFsjshzt(JcyLxjhConstant.JCYLX_CJRY_SJSHZT_SHTG);
            query.setFkhjg(JcyLxjhConstant.JCYLX_CJRY_KHJG_HG);

        }

        if (StringUtils.isNotBlank(query.getGjz())){
            if (query.getGjz().contains("男")){
                query.setSex(1);
            }else if (query.getGjz().contains("女")){
                query.setSex(2);
            }
        }

        return query;
    }

    /**
     * 导出ZIP-遴选采集人员
     * @param state 0: 待审核；1：审核通过；2：审核不通过；3：人员汇总
     */
    public void exportZipLxry(JcyLxUserVo query, OrderItemVo orderItemVo, int state, HttpServletResponse response){
        if(StringUtils.isBlank(query.getIds())) {
            if (StringEmptyUtils.isBlank(query.getFlxjhid())) {
                throw new BusinessException("遴选参数为空！");
            }

            query = ZhQueryTj(query, state);
        }

        List<InputStream> files = new ArrayList<>();
        List<String> fileNames = new ArrayList<>();

        List<JcyLxUserVo> userList = spcyPxJbxxMapper.selectLxjhUserList(query, orderItemVo);
        for (int order = 0; order < userList.size(); order++){

            List<SpcySqsxWjjl> wjjlList = spcySqsxWjjlService.list(new LambdaQueryWrapper<SpcySqsxWjjl>()
                    .eq(SpcySqsxWjjl::getFpid, userList.get(order).getId())
                    .eq(SpcySqsxWjjl::getFwjlx1, LogConstant.LOGS_JCY_LXTJBGZWJ));

            if (CollectionUtil.isNotEmpty(wjjlList) && StringUtils.isNotBlank(wjjlList.get(0).getFcflj())){
                InputStream object = spcyMinioUtils.getObject(wjjlList.get(0).getFcflj());
                if (object == null){
                    continue;
                }
                files.add(object);

                fileNames.add(userList.get(order).getRealname() + "(" +userList.get(order).getFgzdw() +")"+ wjjlList.get(0).getFwjlx());
            }
        }

        PdfUtils.downInputZip(files, fileNames, response);
    }

}
